<template>
  <drawer :show="edit" :styles="{width:'750px'}" pos="right" tran="push" @change-show="changeDrawerShow">
    <div slot="drawer" style="height:100%">
      <edit v-if="edit" :data="selectTable" @getData="getData" @close="edit=false"></edit>
    </div>
    <div class="app-container calendar-list-container">
      <el-table v-loading="!pload" ref="multipleTable" border :data="tableData">
        <el-table-column property="title" label="文章标题" show-overflow-tooltip>
        </el-table-column>
        <el-table-column width="80" property="planName" label="所属计划包">
        </el-table-column>
        <el-table-column label="期限" property="planTimeLimit">
        </el-table-column>
        <el-table-column label="购买人数" align="center" property="planSaleNum">
        </el-table-column>
        <el-table-column label="计划状态" align="center" property="statusText">
        </el-table-column>
        <el-table-column label="发布时间" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="230">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
            <el-button size="mini" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="limit" :page-sizes="limits" background layout="sizes, prev, pager, next, jumper, total" :total="count">
        </el-pagination>
      </div>
    </div>
  </drawer>
</template>

<script>
import * as api from '@/utils/api'
import waves from '@/directive/waves' // 水波纹指令
import edit from './edit'
export default {
  directives: {
    waves
  },
  data() {
    return {
      isStick: 0,
      isStickShow: false,
      tableData: [],
      selection: [],
      searchData: {
        pageNum: 1,
        pageSize: 20
      },
      pload: false,
      edit: false,
      currentPage: 1,
      limit: 20,
      limits: [20, 50, 100],
      count: 0
    }
  },
  components: {
    edit,
    drawer: () => import('@/components/Drawer')
  },
  created() {
    this.getData()
  },
  methods: {
    async handleDelete(index, row) {
      this.$confirm('确认要删除吗', { type: 'warning' }).then(async() => {
        try {
          this.pload = false
          await api.removePlanArtDelete({ articleId: row.articleId })
          this.$notify({ title: '删除成功', type: 'success', duration: 5000 })
          this.searchData.pageNum = 1
          this.getData()
        } catch (e) {
          this.pload = true
        }
      })
    },
    handleEdit(index, row) {
      this.selectTable = JSON.parse(JSON.stringify(row))
      this.selectTable.method = 'edit'
      this.edit = true
    },
    async getData() {
      this.pload = false
      const Datas = await api.getLtsPlanArt({...this.searchData})
      this.tableData = Datas.list
      this.count = Datas.total
      this.pload = true
    },
    async updateStatus (item) {
     await api.ltsQaUpdateStatus({
       questionId: item.questionId,
       forbiddenStatus: ~~!item.forbiddenStatus})
     this.getData()
    },
    handleFilter() {
      this.currentPage = 1
      this.getData()
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val
      this.getData()
    },
    changeDrawerShow(state) {
      this.edit = state
      console.log(state)
    }
  }
}
</script>
<style lang="scss" scoped>
  .input-txt {
    font-size: 13px;
    vertical-align: 4px;
  }
</style>
